﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Argotic.Syndication;
using System.Text.RegularExpressions;

namespace Linkmeme
{
    public static class Extensions
    {
        public static Dictionary<string, string> SourceTypeDict = new Dictionary<string, string>()
        {
            {"blog", "博客"},
            {"photo", "照片"},
            {"bookmark", "书签"},
            {"status", "状态"}
        };
        public static string ToCH(this string word)
        {
            return SourceTypeDict.ContainsKey(word.ToLower()) ? SourceTypeDict[word.ToLower()] : word;
        }
    }


    public static class RssItemExtension
    {
        public static string GetPhotoUrl(this RssItem source, string providerName)
        {
            if (source == null)
                throw new Exception("Rss item can't be null. - GetPhotoUrl");

            string desc = source.Description;

            if (providerName.ToLower() == "flickr")
            {
                Regex re = new Regex(".*(http://farm.*\\.jpg)");
                Match m = re.Match(desc);
                desc = m.Groups[1].Value;
            }

            return desc;
        }
    }
}
